export const Game = {
    player: {
        x: 0,  // 改为相对坐标
        y: 0,
        width: 120,
        height: 120,
        direction: 0,
        speed: 5,
        image: './tank.jpg'
    },
    // 添加新的游戏属性
    camera: {
        x: 0,
        y: 0
    },
    world: {
        width: 1600,
        height: 1200,
        tiles: []
    },
    bullets: [],
    enemies: [],
    keys: {},
    maxEnemies: 10, // 最大敌人数量
    spawnInterval: 1000 // 生成间隔时间
};

export const canvas = document.getElementById('gameCanvas');
export const ctx = canvas.getContext('2d');

// 添加图像加载函数
function loadImage(src) {
    return new Promise((resolve, reject) => {
        const img = new Image();
        img.onload = () => resolve(img);
        img.onerror = () => reject(new Error(`Failed to load image at ${src}`));
        img.src = src;
    });
}

// 在 Game 初始化时加载图像
let enemyImage;
let szImage;
let ssImage;

Promise.all([
    loadImage('./js/dtank.jpg'),
    loadImage('./js/sz.jpg'),
    loadImage('./js/ss.jpg')
])
    .then(images => {
        enemyImage = images[0];
        szImage = images[1];
        ssImage = images[2];
    })
    .catch(error => {
        console.error(error);
    });

export { enemyImage, szImage, ssImage };
